<?php
/**
 * @author spenceryg
 * @date 2022/12/4
 * @time 10:59 上午
 * @focus love & life
 */


namespace app\auto\controller;


use think\facade\View;
use think\response\Json;

class Translate extends \app\BaseController
{
    public  function index()
    {
        $from = input('from');
        $data = \app\common\lib\translate\Translate::where('from', 'like', '%'.$from.'%')->order('id desc')->paginate(15);
        View::assign([
            'data' => $data,
            'paginate' => $data->render()
        ]);
        return View::fetch();
    }


    /**
     * update
     * @return Json
     */
    public function update()
    {
        $data = input();
        validate([
            'from|被翻译词语' => 'require',
            'to|翻译后词语' => 'require',
            'type|默认数据库字段类型' => 'require',
        ])->check($data);
        \app\common\lib\translate\Translate::update($data);
        return success();
    }

    public function delete()
    {
        $id = input('id');
        \app\common\lib\translate\Translate::destroy($id);
        return success();
    }
}
